<template>
  <div class="box">
    <header>
      <div>
        <dl v-for="(item, index) in details" :key="index">
          <dd>
            <p>{{ item.sqname }}</p>
            <p>{{ item.bname }}</p>
            <p><i class="iconfont icon-dianhua"></i>{{ item.brokerid }}</p>
            <p><i class="iconfont icon-xinxi"></i>{{ item.shopname }}</p>
          </dd>
          <dt><img :src="item.brokerimg" /></dt>
        </dl>
      </div>
    </header>
    <main>
      <div class="title">
        <p>
          <span
            v-for="(item, index) in tabs"
            :key="index"
            @click="changeindex(index)"
            :class="tabindex == index ? 'active' : ''"
            >{{ item }}</span
          >
        </p>
        <p>房源:{{ details[0].turnover_cnt }}</p>
      </div>
      <div class="content">
        <div v-if="tabindex == 0" class="c1">
          <dl v-for="(item, index) in houselist" :key="index">
            <dt><img :src="item.imgurl" /></dt>
            <dd>
              <p>{{ item.housetitle }}</p>
              <p>
                <span>{{ item.buildarea }}平方米</span
                ><span>{{ item.communityname }}</span>
              </p>
              <p>
                <span>{{ item.price }}万</span
                ><span>{{ item.unitprice }}元/平方米</span>
              </p>
            </dd>
          </dl>
        </div>
        <div v-if="tabindex == 1" class="c2">
          <dl v-for="(item, index) in rentlist" :key="index">
            <dt><img :src="item.img_url" /></dt>
            <dd>
              <p>{{ item.housetitle }}</p>
              <p>
                <span v-for="(item1, index1) in item.tagwall" :key="index1">{{
                  item1
                }}</span>
              </p>
              <p>
                <span>{{ item.price }}/月</span>
              </p>
            </dd>
          </dl>
        </div>
      </div>
    </main>
    <footer>
      <p>
        <i class="iconfont icon-fenxiang"></i>
        <button type="warn" open-type="share" data-tag="share1" id="btn_share1">
          分享
        </button>
      </p>
      <p>
        <button @click="toDetail(details[0].brokerid)">在线咨询</button>
        <button @click="tel()">电话咨询</button>
      </p>
    </footer>
  </div>
</template>
<script>
import "../../static/agent/iconfont.css";
import agent from "../../static/json/agent.json";
import { getAgentlist, getHouselist } from "../../services/index";
export default {
  data() {
    return {
      details: [],
      tabindex: 0,
      tabs: ["卖房", "租房"],
      list: [],
      houselist: [],
      rentlist: [],
    };
  },
  //获取租房信息
  onShow() {
    this.rentlist = agent.data.list;
  },
  //获取经纪人列表
  async onLoad(options) {
    this.list = await getAgentlist();
    //获取详情id
    let id = options.id;
    //过滤
    this.details = this.list.data.list.filter((item) => item.brokerid == id);
    //获取房屋列表(卖房)
    let res = await getHouselist(id);
    if (res.status == 200) {
      this.houselist = res.data.list;
    }
  },
  methods: {
    //切换高亮
    changeindex(index) {
      this.tabindex = index;
    },
    //跳转聊天页面
    toDetail(id) {
      uni.navigateTo({
        url: "../chat/chat?id=" + id,
      });
    },
    //打电话
    tel() {
      let tel = this.details[0].brokerid;
      let res = String(tel);
      wx.makePhoneCall({
        phoneNumber: res,
        //拨打成功
        success: function (res) {
          console.log(res, "拨打成功");
        },
        //拨打失败
        fail: function (res) {
          console.log(res, "拨打失败");
        },
        //拨打结束
        complete: function (res) {
          console.log(res, "拨打结束");
        },
      });
    },
  },
};
</script>

<style lang='scss' scoped>
.box {
  width: 100%;
  height: 1120rpx;
  display: flex;
  background: #f5f5f5;
  flex-direction: column;
  header {
    width: 100%;
    height: 400rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #2592fa;
    div {
      width: 90%;
      height: 300rpx;
      background: white;
      border: 2px solid #ccc;
      dl {
        width: 100%;
        height: 300rpx;
        margin-left: 20rpx;
        display: flex;
        justify-content: center;
        align-items: center;
        dt {
          width: 300rpx;
          height: 200rpx;
          display: flex;
          justify-content: center;
          align-items: center;
          img {
            width: 200rpx;
            height: 200rpx;
            border-radius: 50%;
          }
        }
        dd {
          width: 300rpx;
          height: 250rpx;
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          align-items: flex-start;
          p:nth-child(1) {
            color: #ccc;
            font-size: 30rpx;
          }
          p:nth-child(2) {
            font-weight: 600;
            font-size: 40rpx;
          }
          p:nth-child(3) {
            display: flex;
            i {
              color: red;
              font-size: 40rpx;
              margin-right: 20rpx;
            }
          }
          p:nth-child(4) {
            display: flex;
            i {
              color: #ccc;
              font-size: 40rpx;
              margin-right: 20rpx;
            }
          }
        }
      }
    }
  }
  main {
    flex: 1;
    overflow: auto;
    .title {
      width: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;
      p:nth-child(1) {
        width: 400rpx;
        height: 100rpx;
        justify-content: space-around;
        display: flex;
        align-items: center;
      }
      p:nth-child(2) {
        margin-right: 30rpx;
      }
    }
    .content {
      width: 100%;
      display: flex;
      flex-direction: column;
      .c1 {
        dl {
          width: 100%;
          height: 300rpx;
          border-bottom: 1px solid #ccc;
          display: flex;
          dt {
            width: 35%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            img {
              width: 94%;
              height: 80%;
            }
          }
          dd {
            width: 60%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: flex-start;
            margin-left: 20rpx;
            p:nth-child(1) {
              width: 100%;
              font-weight: 600;
              font-size: 32rpx;
            }
            p:nth-child(2) {
              width: 100%;
              height: 80rpx;
              display: flex;
              align-items: center;
              justify-content: space-between;
              color: #ccc;
              font-size: 30rpx;
            }
            p:nth-child(3) {
              width: 100%;
              height: 80rpx;
              display: flex;
              align-items: center;
              justify-content: space-between;
              span:nth-child(1) {
                font-weight: 600;
                color: red;
                font-size: 40rpx;
              }
              span:nth-child(2) {
                color: #ccc;
                font-size: 26rpx;
              }
            }
          }
        }
      }
      .c2 {
        dl {
          width: 100%;
          height: 300rpx;
          border-bottom: 1px solid #ccc;
          display: flex;
          dt {
            width: 35%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            img {
              width: 94%;
              height: 80%;
            }
          }
          dd {
            width: 60%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: flex-start;
            margin-left: 20rpx;
            p:nth-child(1) {
              width: 100%;
              font-weight: 600;
              font-size: 32rpx;
            }
            p:nth-child(2) {
              width: 100%;
              height: 80rpx;
              display: flex;
              align-items: center;
              justify-content: flex-start;
              font-size: 26rpx;
              span {
                margin-right: 20rpx;
                display: inline-block;
                width: 100rpx;
                height: 40rpx;
                display: flex;
                justify-content: center;
                align-items: center;
                color: white;
              }
              span:nth-child(1) {
                background: #fa736e;
              }
              span:nth-child(2) {
                background: #d376d6;
              }
              span:nth-child(3) {
                background: #83c05a;
              }
            }
            p:nth-child(3) {
              width: 100%;
              height: 80rpx;
              display: flex;
              align-items: center;
              justify-content: space-between;
              span:nth-child(1) {
                font-weight: 600;
                color: red;
                font-size: 40rpx;
              }
            }
          }
        }
      }
    }
  }
  footer {
    width: 100%;
    height: 100rpx;
    background: white;
    position: fixed;
    bottom: 0rpx;
    left: 0rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    p:nth-child(1) {
      width: 100rpx;
      height: 80rpx;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      button {
        border: none;
        background: white;
        color: black;
        outline: none;
        font-size: 20rpx;
      }
    }
    p:nth-child(2) {
      margin-right: 20rpx;
      display: flex;
      height: 80rpx;
      align-items: center;
      justify-content: center;
      button:nth-child(1) {
        width: 200rpx;
        height: 70rpx;
        display: flex;
        justify-content: center;
        align-items: center;
        background: #fdae69;
        color: white;
      }
      button:nth-child(2) {
        width: 200rpx;
        height: 70rpx;
        display: flex;
        justify-content: center;
        align-items: center;
        background: #fa736e;
        color: white;
      }
    }
  }
}
.active {
  font-weight: 600;
  font-size: 34rpx;
}
</style>